SEARCH SCRIPT HELP!

SEARCH SCRIPT HELP!

am 31.07.2007 08:34:34 von benji

I recently found this search engine script while searching the net
recently and desperately need help with it. The script displays search
hippo results via xml feed and the sponsored results on the right hand
side are from revenue pilot. The script works except there is a bug.
The first query works fine (it displays 10 results per page) however
when you click "next" to go to the next page it will display 15 and
next page it will display 20 then 25 and so on. The other problem is
that the table size of the search hippo results on the odd occasion
will get bigger and will throw the revenue pilot results on the right
hand side out of view. I imagine that someone with knowledge of these
things would be able to rectify it quite easily, however this is a bit
above my head. If somebody could help me with this it will be very
much appreciated.

Here is the search results file (search.php)



// (C) 2003 C P Ridings
// Create a search engine the easy way using searchhippo and
revenuepilot

// Change the layout by editing the index.html page and the template
results.tpl

// This is a revenuepilot affiliate id for the paying side ads.
// If you want to use your own id here you MUST get it from
http://www.revenuepilot.com/iebar/ ONLY

$revid=1833;

// Class to hold the SearchHippo results
class shItem {
var $shTitle;
var $shDescription;
var $shURL;
var $shDispURL;
}

// Class to hold the RevenuePilot Ads
class rpAds {
var $rpTitle;
var $rpLink;
var $rpDomain;
var $rpDescription;
}

$sTitle = "";
$sLink = "";
$sDescription = "";
$arItems = array();
$itemCount = 0;
$resultscount=0;
$nexturl="";
$prevurl="";
$theirip=$_SERVER['REMOTE_ADDR'];
$adsItems = array();
$adscount = 0;
$curTag="";

function startElement($parser, $name, $attrs) {
global $curTag, $prevurl, $nexturl;
$curTag .= "^$name";
if ($name == "RESULTS") {
// Get the results count and previous and next urls
$resultscount=trim($attrs["COUNT"]);
$nexturl=trim($attrs["NEXTURL"]);
$prevurl=trim($attrs["PREVURL"]);
}
}

function endElement($parser, $name) {
global $curTag;
$caret_pos = strrpos($curTag,'^');
$curTag = substr($curTag,0,$caret_pos);
}


function characterData($parser, $data) {
global $curTag;

// now get the items
global $arItems, $itemCount;
$itemTitleKey = "^SEARCHHIPPO^RESULTS^RECORD^TITLE";
$itemLinkKey = "^SEARCHHIPPO^RESULTS^RECORD^URL";
$itemDispKey = "^SEARCHHIPPO^RESULTS^RECORD^DISPURL";
$itemDescKey = "^SEARCHHIPPO^RESULTS^RECORD^DESCR";
if ($curTag == $itemTitleKey) {
// make new xItem
$arItems[$itemCount] = new shItem();
// set new item object's properties
$arItems[$itemCount]->shTitle = $data;
}
elseif ($curTag == $itemLinkKey) {
$arItems[$itemCount]->shURL = $data;
}
elseif ($curTag == $itemDescKey) {
$arItems[$itemCount]->shDescription = $data;
}
elseif ($curTag == $itemDispKey) {
$arItems[$itemCount]->shDispURL = $data;
$itemCount++;
}
}

function rpstartElement($parser, $name, $attrs) {
global $curTag, $adsItems, $adscount;
$curTag .= "^$name";
if ($name == "LISTING") {
$adsItems[$adscount] = new rpAds();
$adsItems[$adscount]->rpTitle = trim($attrs["TITLE"]);
$adsItems[$adscount]->rpLink = trim($attrs["LINK"]);
$adsItems[$adscount]->rpDomain = trim($attrs["DOMAIN"]);
$adsItems[$adscount]->rpDescription = trim($attrs["DESCRIPTION"]);
$adscount++;
}
}

function rpendElement($parser, $name) {
global $curTag;
$caret_pos = strrpos($curTag,'^');
$curTag = substr($curTag,0,$caret_pos);
}


function rpcharacterData($parser, $data) {
}

if ($HTTP_GET_VARS) {
$q=$HTTP_GET_VARS['q'];
} else {
$q="";
}

if ($HTTP_GET_VARS) {
$c=$HTTP_GET_VARS['c'];
} else {
$c=0;
}

if ($HTTP_GET_VARS) {
$ir=$HTTP_GET_VARS['i'];
} else {
$ir=0;
}

if ($q == "") {
echo "This is the front page which hasn't been done yet!";
} else {
// Get the SearchHippo XML document
$docurl = "http://www.searchhippo.com/qxml.php?q=" .
urlencode($q) . "&c=" . $c . "&i=" . $ir;
$handle = fopen ($docurl, "r");
$data = "";
while (!feof($handle)) {
$data .= fread($handle, 4096);
}
// Fire up the XML parser
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement",
"endElement");
xml_set_character_data_handler($xml_parser, "characterData");
xml_parse($xml_parser, $data);
xml_parser_free($xml_parser);
$results="";
for ($il = 0; $il < $itemCount; $il++) {
$results.= "";
$results.= "shURL .
"\">";
$results.= $arItems[$il]->shTitle;
$results.= "

\n";
$results.= $arItems[$il]->shDescription . "
";
$results.= "
\"#6ec46b\">";
$results.= $arItems[$il]->shDispURL . " font>

";
}
fclose ($handle);
// Get RevenuePilot Links
$docurl = "http://search.revenuepilot.com/servlet/search?
mode=xml&id=" . $revid . "&filter=off&perpage=4&ip=" . $theirip .
"&skip=0&keyword=" . urlencode($q);
$handle = fopen ($docurl, "r");
$data = "";
while (!feof($handle)) {
$data .= fread($handle, 4096);
}
$rpxml_parser = xml_parser_create();
xml_set_element_handler($rpxml_parser, "rpstartElement",
"rpendElement");
xml_set_character_data_handler($rpxml_parser, "rpcharacterData");
xml_parse($rpxml_parser, $data);
xml_parser_free($rpxml_parser);
$ads = "";
for ($il = 0; $il < $adscount; $il++) {
$ads.= "

cellpadding=\"5\" width=\"170\" bgcolor=\"#FFFFFF\"> $adsItems[$il]->rpLink . "\">
\"self.location='" . $adsItems[$il]->rpLink . "'\" style=
\"cursor:hand; cursor:pointer\">";
$ads.= "";
$ads.= "rpLink . "\">";
$ads.= $adsItems[$il]->rpTitle;
$ads.= "

\n";
$ads.= $adsItems[$il]->rpDescription . "
";
$ads.= "
\"#7ec47b\">" . $adsItems[$il]->rpDomain . "\n";
$ads.= "

";
}
fclose ($handle);
$handle = fopen ("./results.tpl", "r");
$data = fread ($handle, 1000000);
$data = str_replace("[ADS]", $ads, $data);
$data = str_replace("[RESULTS]", $results, $data);
$data = str_replace("[QUERY]", $q, $data);
$prevl = "";
$nextl = "";
if ($prevurl != "") {
$rc=$c-10;
$rir=$ir-10;
$prevl = "Previous";
}
if ($nexturl != "") {
$rc=$c+10;
$rir=$ir+10;
$nextl = "Next";
}
$data = str_replace("[NEXT]", $nextl, $data);
$data = str_replace("[PREV]", $prevl, $data);
echo $data;
}

?>




HERE IS THE TEMPLATE FILE (results.tpl)





[QUERY] :: Results








Easy Search font>


name="q" value="[QUERY]">  value="0"> value="Search">

size="2">Brought to you by SearchGuild.com






Searched For:
[QUERY]








[RESULTS] [ADS]

[PREV]  [NEXT]








©2003 href="http://www.searchguild.com/">SearchGuild.com a>          Powered
by SearchHippo




please email me on webster.81@gmail.com thanks